3 ...\PTVR_Researchers\Python_Scripts\Demos\Pointing\laser_pointing.py
6 Goal : illustrate the use of the Pointing Laser.
9 What you see: if you point at the red sphere (sphere_1) with the laser beam,
10 it will turn blue. This is an INTERACTION between an EVENT and a
13 Note on the pointing cone (surrounding the laser beam):
14 It can be displayed or not thanks to the 'display_pointing_cone'
15 parameter (True or False). The default in this demo is True.
18 Important note concerning scripts that use handcontrollers:
19 It is necessary to specify your VR system's manufacturer if:
20 a/ your code contains a PointedAt Event triggered by a handcontroller
22 b/ your code contains a PointingLaser () object.
23 This is specified in the The3DWorld() in the following way:
24 headset_manufacturer = "Vive" (default) refers to the HTC Vive pro series headsets.
25 headset_manufacturer = "Oculus" refers to the Quest 1, 2 or 3 headsets (in keeping
26 with OpenXR terminology).
28 my_world = The3DWorld (
29 headset_manufacturer = "Vive" # "Vive" by default
32 Things to check in the PointingLaser object when using different
33 headset manufacturers:
34 ex. With the Quest, you should do
35 laser_beam_x_y_rotation = np.array([60, 0]) # 60 ° about X axis
36 in the PointingLaser () object.
37 Otherwise the laserbeam will be directed upwards in an awkward and non
39 See details on the laser beam axis in the laser_beam_axis.py demo script.
58 my_laser_color = color.RGBColor(r=0.7, g=0.5)
59 hand = LaserContingency.RIGHT_HAND
60 my_activation_cone_radius_deg = 2
63 sphere_size = np.array([1, 1, 1])
65 sphere_1_color = color.RGBColor(1, 0, 0)
66 sphere_1_pos = np.array([-2, 0, 3])
67 sphere_2_color = color.RGBColor(0, 1, 0)
68 sphere_2_pos = np.array([0, 0, 5])
69 sphere_3_color = color.RGBColor(0, 0, 1)
70 sphere_3_pos = np.array([2, 0, 7])
71 new_color = color.RGBColor(b=1, g=1)
77 headset_manufacturer =
"Vive"
89 if (hand == LaserContingency.RIGHT_HAND):
90 is_right_controller_visibility =
True
91 is_left_controller_visibility =
False
92 my_activation_cone_origin_id = my_world.handControllerRight.id
93 if (hand == LaserContingency.LEFT_HAND):
94 is_left_controller_visibility =
True
95 is_right_controller_visibility =
False
96 my_activation_cone_origin_id = my_world.handControllerLeft.id
98 my_scene =
VisualScene(is_left_hand_controller_visible=is_left_controller_visibility,
99 is_right_hand_controller_visible=is_right_controller_visibility)
103 laser_color=my_laser_color,
105 my_scene.place_pointing_laser(my_laser_beam)
108 sphere_1 =
Sphere(size_in_meters=sphere_size, color=sphere_1_color,
109 position_in_current_CS=sphere_1_pos)
110 sphere_2 =
Sphere(size_in_meters=sphere_size, color=sphere_2_color,
111 position_in_current_CS=sphere_2_pos)
112 sphere_3 =
Sphere(size_in_meters=sphere_size, color=sphere_3_color,
113 position_in_current_CS=sphere_3_pos)
115 my_scene.place(sphere_1, my_world)
116 my_scene.place(sphere_2, my_world)
117 my_scene.place(sphere_3, my_world)
122 target_id = sphere_1.id,
123 activation_cone_origin_id = my_activation_cone_origin_id,
124 activation_cone_radius_deg = my_activation_cone_radius_deg,
125 display_pointing_cone =
True
129 target_id = sphere_1.id,
130 activation_cone_origin_id = my_activation_cone_origin_id,
131 activation_cone_radius_deg = my_activation_cone_radius_deg,
132 display_pointing_cone =
True,
137 object_id=sphere_1.id,
140 object_id=sphere_1.id,
143 my_scene.AddInteraction(events=[sphere_1_is_pointed_at],
144 callbacks=[change_sphere_1_color])
145 my_scene.AddInteraction(events=[sphere_1_is_not_pointed_at],
146 callbacks=[change_sphere_1_color_back])
148 my_world.add_scene(my_scene)
152 if __name__ ==
"__main__":
def LaunchThe3DWorld(jsonFileCategory="Externals")